package com.sky.handle;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.sky.context.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
@Component
public class MyMetObjecthandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("自动insert填充字段开始。。。");
        //设置当前记录的创建时间和修改时间
        metaObject.setValue( "createTime",LocalDateTime.now());
        metaObject.setValue("updateTime",LocalDateTime.now());
        //把存储在线程的id提取出来
        metaObject.setValue("createUser", BaseContext.getCurrentId());
        metaObject.setValue("updateUser",BaseContext.getCurrentId());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("自动iupdate填充字段开始。。。");
        metaObject.setValue("updateTime",LocalDateTime.now());
        //把存储在线程的id提取出来
        metaObject.setValue("updateUser",BaseContext.getCurrentId());
    }
}
